import cv2
import numpy as np
import os


class Parameter:
    rootDir = os.getcwd()
    assetRootDir = rootDir + "/asset"
    resultRootDir = rootDir + "/result"


if __name__ == "__main__":
    img_path = Parameter.assetRootDir + "/parrot.jpg"
    result_dir = Parameter.resultRootDir + "/task2"

    # 读取图片
    image = cv2.imread(img_path)

    # 分离三个通道（B、G、R）
    b, g, r = cv2.split(image)

    # 创建全黑图像（用于填充缺失的通道）
    zeros = np.zeros_like(b)

    # 分别显示每个通道
    b_img = cv2.merge([b, zeros, zeros])
    g_img = cv2.merge([zeros, g, zeros])
    r_img = cv2.merge([zeros, zeros, r])

    # 保存结果
    cv2.imwrite(result_dir + "/blue_parrot.jpg", b_img)
    cv2.imwrite(result_dir + "/green_parrot.jpg", g_img)
    cv2.imwrite(result_dir + "/red_parrot.jpg", r_img)
